package com.github.limit.holder;


import com.github.limit.annotation.MethodAccessLimit;
import com.github.limit.web.LimitDataController;
import org.springframework.context.ApplicationContext;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

/**
 * @author: wangdejun
 * @create: 2019-10-14 12:26
 **/
public class DynamicSettingLimitAnnotationHolder extends AbstractLimitAnnotationHolder {

    @Override
    public void initMethodAnnotation(ApplicationContext applicationContext) throws Exception {

        MethodAccessLimit methodAccessLimit = new MethodAccessLimit() {
            @Override
            public Class<? extends Annotation> annotationType() {
                return MethodAccessLimit.class;
            }

            @Override
            public TimeUnit timeUnit() {
                return TimeUnit.SECONDS;
            }

            @Override
            public long limit() {
                return 10;
            }

            @Override
            public int order() {
                return 10;
            }
        };
        Method method = LimitDataController.class.getMethod("limitDataList");

        setMethodAnnotation(method, methodAccessLimit);
    }


}
